home *** CD-ROM | disk | FTP | other *** search
- Path: qualcomm.com!usenet
- From: nabbasi@qualcomm.com (Nasser Abbasi)
- Newsgroups: comp.lang.c++
- Subject: Re: Virtual Function in private part?
- Date: 7 Feb 1996 22:59:48 GMT
- Organization: QUALCOMM
- Message-ID: <4fbat4$o80@qualcomm.com>
- References: <4fa52o$pkb@news1.usa.pipeline.com>
- NNTP-Posting-Host: nabbasi.qualcomm.com
- Mime-Version: 1.0
- X-Newsreader: WinVN 0.93.14
-
- In article <4fa52o$pkb@news1.usa.pipeline.com>, grantp@usa.pipeline.co
- says...
- >
- >On Feb 06, 1996 10:29:52 in article <Virtual Function in private part?>,
- >'g9326161@mcmail.cis.McMaster.CA (Hong Shen)' wrote:
- >
- >
- >>Is there any reasons to make a member function in the private section
- of
- >>a class virtual?
- >>
-
- >Sure, for example:
- >
- >class A { public:
- >void Expand { Left = MakeChild(); Right = MakeChild(); }
- >private:
- >virtual A * MakeChild() { return new A; }
- >A * Left; A * Right;
- >};
- >
- >class B {
- > private:
- > virtual A* MakeChild() { return new B; }
- >};
- >
- >Now, when you call Expand, the appropriate types of
- >objects will be constructed.
- >
- >
-
- In your class B, the MakeChild() is declared to return pointer to A,
- yet it returns a pointer to B. Do you not need to do type conversion
- here?
-
- Will this compile without errors or at least a warning?
-
- Nasser
-
-